﻿#include <qg/qg.h>

int main(void)
{
	k_mesg("POLY LINE TEST\n");

	qgDevice* dev = qgDevice::New("", 640, 480, QGSDF_MSAA | QGSDF_LAYOUT);

	if (dev)
	{
		qgStub* stub = dev->GetStub();
		qgFreeType* font = qgFreeType::New();

		tpl::Rect bound(150, 150, stub->GetSize().x - 150, stub->GetSize().y - 150);
		tpl::Point vx[4] =
		{
			tpl::Point(bound.left, bound.top),
			tpl::Point(bound.right, bound.top),
			tpl::Point(bound.right, bound.bottom),
			tpl::Point(bound.left, bound.bottom),
		};

		tpl::ColorValue vc[] =
		{
			tpl::ColorValue(0xFFFF0000),
			tpl::ColorValue(0xFF00FF00),
			tpl::ColorValue(0xFF0000FF),
			tpl::ColorValue(0xFFFFFFFF),
		};

		//
		float f = 0.0f, dt = 128.0f;

		//
		while (dev->Run())
		{
			float adv = stub->GetAdvance();

			//
			f += dt*adv;
			if (f > 255.0f)
			{
				dt = -128.0f;
				f = 255.0f;
			}
			else if (f < 64.0f)
			{
				dt = 128.0f;
				f = 64.0f;
			}

			kint n = (kint)f;
			vc[0].r = n;
			vc[1].g = n;
			vc[2].b = n;
			vc[3].r = n;
			vc[3].g = n;
			vc[3].b = n;

			//
			dev->Enter();

			dev->DrawPolyLine(4, vx, vc);

			font->WriteFormat(5, 5, 0, "[%.2f]", stub->GetRunFps());

			dev->Leave();
			dev->Flush();
		}

		font->Unload();
		dev->Unload();
	}

	return 0;
}
